package com.uxwine.view;

import com.uxwine.alarm.R;
import com.uxwine.view.t.DialView;

import android.app.ActionBar.LayoutParams;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

public class SlideWindow extends PopupWindow {
	
	private Context mCtx;
	private OnWindowEventListener mOnWindowEventListener;
	
	public SlideWindow(Context ctx)
	{
		super(ctx);
		mCtx = ctx;
		initView();
	}
	
	private void initView()
	{
		this.setFocusable(true);
		setAnimationStyle(R.style.SlideWindow);
		setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
		setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
		setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
				WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
		
		
		//ZZM：设置背景，不容易哇
		ColorDrawable cd = new ColorDrawable(-00000);
		setBackgroundDrawable(cd);
	}
	
	protected Context getContext()
	{
		return mCtx;
	}
	
	public void setOnWindowEventListener(OnWindowEventListener l)
	{
		mOnWindowEventListener = l;
	}
	
	public void setContentView(int resId)
	{
		View v = LayoutInflater.from(mCtx).inflate(resId, null);
		setContentView(v);
	}
	
	public View findViewById(int id)
	{
		return getContentView().findViewById(id);
	}
	
	public void exit(int code) {
		dismiss();
		if(null != mOnWindowEventListener)
			mOnWindowEventListener.onExit(code);
	}

	public static interface OnWindowEventListener
	{
		public void onExit(int code);
	}
}
